package jam.network.message;

import java.util.*;

//
// =============================================================================
//

public abstract class ServerMessage extends Message {    
    /**
     * Returns a list of the arguments to be included when creating the network
     * string for the message.
     *
     * @return The argument list.
     */
    public abstract List<String> getArgumentList();
    
    /**
     * Returns a string that represents the message for sending over the network
     * for our protocol.
     *
     * @return A protocol string representation of the message.
     */
    public final String toString() {
        // Build the argument string.
        StringBuilder sb = new StringBuilder();
        Iterator<String> args = this.getArgumentList().listIterator();
        while (args.hasNext() == true) {
            String arg = args.next();      
            if (args.hasNext() == true)
                sb.append(String.format("%s:", arg));
            else
                sb.append(String.format("%s", arg));       
        }
        
        return String.format("%s:%d:%s", this.getKeyword(), this.transactionId,
                sb);
    }
    
    //
    // =========================================================================
    //
    
    /**
     * Constructor.
     * 
     * @param transactionId The message's transaction ID
     */
	protected ServerMessage(int transactionId) {
		super(transactionId);
	}
}